import subprocess
import IPy


def st():
    ips = IPy.IP("192.168.0.0/24")
    for ip in ips:
        ip1 = str(ip)
        req = subprocess.call('ping -c 1 %s &> /dev/null' %ip1,shell=True)
        if req==0:
            subprocess.call('echo %s >> /root/shell/up.txt' %ip1,shell=True)
        else:
            subprocess.call('echo %s >> /root/shell/down.txt' %ip1,shell=True)
    with open("/root/shell/up.txt") as f:
        data = f.read()
        print(data)
        f.close()

st()

# "ping","-c","1",ip,"&>","/dev/null","&&","echo",ip,">>","/root/shell/up.txt","||","echo",ip,">>","/root/shell/down.txt"

# def runcmd1():
#     subprocess.run(["/root/shell/scan_ip.sh"])
#     with open("/root/shell/up.txt") as f:
#         data = f.read()
#         print(data)
#         f.close()
